/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Converter;

import dao.ProfDAO;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import Bean.Professor;
import javax.faces.convert.FacesConverter;
import javax.naming.InitialContext;

/**
 *
 * @author alexandre
 */
@FacesConverter(value = "ProfessorConverter")
public class ProfessorConverter implements Converter{

     private ProfDAO getSession() {
        try {
            return (ProfDAO) new InitialContext().lookup("java:global/SIAC4/ProfDAO");
        } catch (Exception ex) {
            throw new IllegalArgumentException(ex);
        }
    }
     
     
    Professor professor;
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        ProfDAO instance = getSession();
        Integer id = Integer.valueOf(value);
        professor = instance.getProfessorID(id);
        return professor;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        professor = (Professor)value;
        if(professor != null){
            return String.valueOf(professor.getID());
        }
        else{
            return null;
        }
        
    }
    
}
